package com.samphanie.admin.modules.sys.controller;

import com.samphanie.admin.modules.sys.domain.vo.MenuVo;
import com.samphanie.admin.modules.sys.domain.vo.RouteVo;
import com.samphanie.admin.modules.sys.service.IMenuService;
import com.samphanie.common.utils.ApiResponse;
import com.samphanie.mbg.model.sys.SysMenu;
import com.samphanie.mbg.utils.PageUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.awt.*;
import java.util.List;
import java.util.Map;

/**
 * @author ZSY
 * @date 2021/11/8 15:12
 */
@Slf4j
@Api(tags = "menu")
@RestController
@RequestMapping("/api/v1/menu")
@RequiredArgsConstructor
public class MenuController {

    private final IMenuService menuService;

    @ApiOperation("动态路由列表")
    @GetMapping("/queryDynamicRoutes")
    public ApiResponse<List<RouteVo>> queryDynamicRoutes() {
        List<RouteVo> list = menuService.queryDynamicRoutes();
        return ApiResponse.success(list);
    }

    @ApiOperation("菜单分页列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "页码", paramType = "query", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "显示条数", paramType = "query", dataTypeClass = Integer.class)
    })
    @GetMapping("/listPage")
    public ApiResponse<PageUtils> menuListPage(@ApiIgnore @RequestParam Map<String, Object> parameters) {
        return ApiResponse.success(menuService.listPage(parameters));
    }

    @ApiOperation("树形菜单列表")
    @GetMapping("/menuTreeList")
    public ApiResponse<List<MenuVo>> menuTreeList() {
        return ApiResponse.success(menuService.menuTreeList());
    }

    @ApiOperation("菜单详情")
    @ApiImplicitParam(name = "menuId", value = "菜单ID", paramType = "path", dataTypeClass = Long.class)
    @GetMapping("/{menuId}")
    public ApiResponse<MenuVo> menuInfo(@PathVariable("menuId") Long menuId) {
        MenuVo menuVo = menuService.queryMenuVoById(menuId);
        return ApiResponse.success(menuVo);
    }

}
